Ext.define('App.controller.car.CarViewController', {
	extend : 'Ext.app.ViewController',
	alias : 'controller.carViewController',
	menu : Ext.widget('menu'),
	control : {
		'carView carSearch basesearchform' : {
			beforerender : function(form) {
				var buttons = {
					'bs/car/saveCar' : function(permit) {
						var carTypeId = form.down("carTypeSingleSelect").down("[itemId=carTypeId]").getValue();
						if(!carTypeId){
                            BaseUtil.toast("请选择车型");
                            return;
						}
						var name = form.down("[name=name]").getValue();
						if(!name){
                            BaseUtil.toast("请填写车名");
                            return;
						}
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('car.CarStore').reload();
                        },form.getValues());

					},
                    'bs/car/updateCar' : function(permit) {
                        var carTypeId = form.down("carTypeSingleSelect").down("[itemId=carTypeId]").getValue();
                        if(!carTypeId){
                            BaseUtil.toast("请选择车名");
                            return;
                        }
                        var name = form.down("[name=name]").getValue();
                        if(!name){
                            BaseUtil.toast("请填写车名");
                            return;
                        }
                        BaseUtil.post(permit.url,function(data){
                            BaseUtil.toast(data.msg);
                            Ext.StoreMgr.get('car.CarStore').reload();
                        },form.getValues());

                    }
				};
				BaseUtil.createPermitBar(form, buttons);
			},
			render : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('car.CarStore'),Ext.getCmp('carView').down('carSearch form').getForm().getFieldValues());
			}
		},
        'carView carList':{
            itemclick:function(view, record, item, index, e, eOpts){
                var search  =  Ext.getCmp('carView').down('carSearch form');
                search.reset();
                search.loadRecord(record);
                search.down("carTypeSingleSelect").down("[itemId=carTypeId]").setValue(record.get("carTypeId"));
                search.down("carTypeSingleSelect").down("[itemId=name]").setValue(record.get("typeName"));
            },
        },
		'carView carSearch [action=search] ' : {
			click : function() {
				BaseUtil.loadStore(Ext.StoreMgr.get('car.CarStore'),Ext.getCmp('carView').down('carSearch form').getForm().getFieldValues());
			}
		}
	}
});